﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>MouseMove - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The MouseMove function moves the mouse cursor." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>MouseMove</h1>

<p>Moves the mouse cursor.</p>

<pre class="Syntax"><span class="func">MouseMove</span> X, Y <span class="optional">, Speed, Relative</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>X, Y</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The x/y coordinates to move the mouse to. Coordinates are relative to the active window unless <a href="CoordMode.htm">CoordMode</a> was used to change that.</p>
  </dd>

  <dt>Speed</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>移动鼠标的速度, 介于 0(最快) 和 100(最慢) 之间.</p>
    <p class="note"><strong>注意</strong>: 速度为 0 表示瞬时移动鼠标.</p>
    <p>如果省略, 则使用默认速度(由 <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> 设置, 否则为 2).</p>
    <p><em>Speed</em> is ignored for <a href="SendMode.htm">SendInput/Play modes</a>; they move the mouse instantaneously (though <a href="SetMouseDelay.htm">SetMouseDelay</a> has a mode that applies to SendPlay). To visually move the mouse more slowly -- such as a script that performs a demonstration for an audience -- use <code><a href="Send.htm#Click">SendEvent {Click 100, 200}</a></code> or <code><a href="SendMode.htm">SendMode</a> Event</code> (optionally in conjuction with <a href="BlockInput.htm">BlockInput</a>).</p>
  </dd>

  <dt>Relative</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>如果省略, 则将 X 和 Y 坐标视为绝对值. 要更改此行为, 请指定下面的字母:</p>
    <p><strong>R:</strong> The X and Y coordinates will be treated as offsets from the current mouse position. In other words, the cursor will be moved from its current position by X pixels to the right (left if negative) and Y pixels down (up if negative).</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p>这个函数使用 <a href="SendMode.htm">SendMode</a> 设置的发送方法.</p>
<p>The <a href="SendMode.htm">SendPlay mode</a> is able to successfully generate mouse events  in a broader variety of games than the other modes. In addition, some applications and games may have trouble  tracking the mouse if it moves too quickly. The <em>speed</em> parameter or <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a> can be used to reduce the speed (in the default <a href="SendMode.htm">SendEvent mode</a> only).</p>
<p>可以使用 <a href="BlockInput.htm">BlockInput</a> 函数 防止用户对鼠标的任何物理操作干扰由鼠标函数产生的模拟鼠标事件. 不过, 在 <a href="SendMode.htm">SendInput/Play</a> 模式中通常不需要这样做, 因为它们会自动将用户对鼠标的物理操作延迟到发送之后.</p>
<p>There is an automatic delay after every movement of the mouse (except for <a href="SendMode.htm">SendInput mode</a>). Use <a href="SetMouseDelay.htm">SetMouseDelay</a> to change the length of the delay.</p>
<p>The following is an alternate way to move the mouse cursor that may work better in certain multi-monitor configurations:</p>
<pre><a href="DllCall.htm">DllCall</a>(&quot;SetCursorPos&quot;, &quot;int&quot;, 100, &quot;int&quot;, 400)  <em>; The first number is the X-coordinate and the second is the Y (relative to the screen).</em></pre>
<p>On a related note, the mouse cursor can be temporarily hidden via the <a href="DllCall.htm#ExHideCursor">hide-cursor example</a>.</p>
<h2 id="Related">相关</h2>
<p><a href="CoordMode.htm">CoordMode</a>, <a href="SendMode.htm">SendMode</a>, <a href="SetDefaultMouseSpeed.htm">SetDefaultMouseSpeed</a>, <a href="SetMouseDelay.htm">SetMouseDelay</a>, <a href="Click.htm">Click</a>, <a href="MouseClick.htm">MouseClick</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a>, <a href="MouseGetPos.htm">MouseGetPos</a>, <a href="BlockInput.htm">BlockInput</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a>: Move the mouse to a new position:</p>
<pre>MouseMove 200, 100</pre>
</div>

<div class="ex" id="ExAdvanced">
<p><a href="#ExAdvanced">#2</a>: Move the mouse slowly (speed 50 vs. 2) by 20 pixels to the right and 30 pixels down from its current location:</p>
<pre>MouseMove 20, 30, 50, "R"</pre>
</div>

</body>
</html>